
//题目链接：https://leetcode.cn/problems/remove-linked-list-elements/
class Solution 
{
public:
    ListNode* removeElements(ListNode* head, int val) 
    {
        ListNode newhead(0,head);
        ListNode *cur=&newhead;
        while(cur->next)
        {
            ListNode* Next=cur->next;
            if(Next->val==val)
            {
                //如果删除了，cur的next依旧是未知节点，需要继续判断
                cur->next=Next->next;
                delete Next;
            }
            else//如果没有删除，才向下
                cur=Next;
        }
        return newhead.next;
    }
};